<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/8/13/013
 * Time: 16:38
 */

namespace app\index\controller;

use app\common\model;
use app\common\controller\Frontend;

class Cart extends Frontend
{
    protected $noNeedRight=['*'];

    //加入购物车
    public function add(){
        if($this->request->isPost()){
            $param = $this->request->post();
            if($param){
//                id,user_id,sellerproduct_id,num,price,product_name,image,totalprice,status(已支付,未支付,已删除)
                $product = db('sellerproduct')->where('id',$param['sellerproduct_id'])->find();
                $data = [
                    'user_id' => $this->auth->id,
                    'sellerproduct_id' => $param['sellerproduct_id'],
                    'num' => '1',
                    'price' => ''
                ];
                $cart = new model\Cart();
                $result = $cart->allowField(true)->save();
                if($result){
                    echo '加入成功';
                    return;
                }
            }
        }
        echo '----';
    }
}